(function(){
	var viewStatus = {
		Compling : "compling",
		Init : "init",
		Load : "load",
		Request : "reqeust",
		Complete : "complete",
		AllCompete:"allComplete"
	}
	
	   var view = $.IObject( {
	   		init:function(op){
	   			//初始化个阶段的委托方法
	   			//this.beforeInit =  $.Callbacks();
	   			this.onInit  =  $.Callbacks();
	   			//this.beforeLoad =  $.Callbacks();
	   			this.onLoad = $.Callbacks();
	   			this.beforeComplete = $.Callbacks();
	   			this.onComplete = $.Callbacks();
	   			//动态运行函数的参数名数组
	   			this._innerArguments = ["page"];
	   			//动态运行函数的参数
	   			this._innerObject = [this];
	   			
	   			$.extend(this,op);
	   			this.compile();
	   		},
	   		/**编辑阶段**/
	   		compile:function(){
	   			var page = this;
	   			this.status = viewStatus.Complie;
	   			//获取编译之后的方法生成器
	   			var builder = Ccay.Jml(page.template,page),html;
	   			//将方法生成器编译成模板方法
				if(this.template = builder.compile(this._innerArguments))
				{
					html = this.callFn(this.template);
				}
	   			this.status = viewStatus.Init;
	   			//执行初始化的委托方法
	   			page.onInit.fireWith(page);
	   			page._load(html);
	   		},
	   		/**加载阶段**/
	   		_load:function(html){
	   			this.status = viewStatus.Load;
	   			//将生成的模板内容加载到目标对象中
	   			$(this.target).html(html);
	   			this.onLoad.fireWith(this);
	   			this._request();
	   		},
	   		/**请求阶段**/
	   		_request:function(){
	   			this.status = viewStatus.Request;
	   			this._complete();
	   		},
	   		/**完成阶段**/
	   		_complete:function(){
	   			var view = this;
	   			this.status = viewStatus.Complete;
	   			this.beforeComplete.fireWith(this);
	   			this.onComplete.fireWith();
	   			
//	   			if(this._destoryObject.length) 
//	   			{
//	   				$.each(this._destoryObject,function(i,name){
//	   					view[name] = null;
//	   				});
//	   			}
//	   			this._innerArguments = this._innerObject = this._destoryObject = null;
	   		},
	   		/**设置视图对象方法
	   		 *  @param {object} op : 参数选项,op.name参数名
	   		 *  @param {object} obj : 参数对象
	   		 */
	   		setObject : function(op,obj){
	   			this._innerArguments.push(op.name);
	   			this._innerObject.push(obj);
//	   			if(!op.durable)
//	   				this._destoryObject.push(op.name);
	   				
	   			this[op.name] = obj;
	   		},
	   		/** 使用view内置对象参数，将字符串编译成方法
	   		 *  @param {string} fnStr : 参数选项,op.name参数名
	   		 *  @param {boolean} fire : 是否立即执行
	   		 */
	   		buildFn:function(fnStr,fire){
	   			var fn;
	   			try{
	   				 fn = new Function(this._innerArguments,fnStr + ';');
	   			}
	   			catch (ex){
	   				Ccay.Core.log(fnStr);
	   				throw new Error(ex);
	   				
	   			}
	   			if(fn && fire)
	   			  return this.callFn(fn);
	   			  
	   			return fn;
	   		},
	   		/** 使用view内置对象参数运行方法
	   		 *  @param {string} fnStr : 参数选项,op.name参数名
	   		 *  @param {boolean} fire : 是否立即执行
	   		 */
	   		callFn : function(fn){
	   			return fn.apply(this,this._innerObject);
	   		}
	   });
	   
	   Ccay.Module.load = function(target,url){
	   		var template = $.create('div');
	   		template.ccayLoad(url,function(){
	   			var page = new view({
	   				template : template,
	   				target : target
	   			});
	   		});
	   }
})();